#include<bits/stdc++.h>
using namespace std;
inline char gc(){
	static char buf[1000000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int read(){
	int sum=0,f=0;
	char ch=gc();
	for(;!isdigit(ch);ch=gc())f|=(ch=='-');
	for(;isdigit(ch);ch=gc()) sum=((sum<<1)+(sum<<3)+(ch^48));
	return f?-sum:sum;
}
const int NN=1e7+4,P=1e9+7;
typedef long long ll;
int a[NN],q[NN],val[NN],last[NN];
ll f[NN];
int main()
{
    int n=read(),k=read();
    for(int i=1;i<=n;i++)
        a[i]=read();
    int head=1,tail=0;
    for(int i=1;i<=n;i++)
    {
        if(head<=tail&&q[head]<=i-k)
        {
            if(head==tail||q[head+1]!=q[head]+1)
            {
                val[q[head]+1]=val[q[head]];
                q[head]++;
                if(head<tail&&f[q[head]-1]+val[q[head]]>f[q[head+1]-1]+val[q[head+1]])
                    head++;
            }
            else
                head++;
        }
        while(head<tail&&val[q[tail-1]]<a[i])
            tail--;
        if(head<=tail&&val[q[tail]]<a[i])
        {
            while(last[q[tail]]&&max(last[q[tail]],i-k+1)<q[tail]&&(head==tail||max(last[q[tail]],i-k+1)>q[tail-1])&&val[last[q[tail]]]<=a[i])
                q[tail]=max(last[q[tail]],i-k+1);
            val[q[tail]]=a[i];
            if(last[q[tail]]&&max(last[q[tail]],i-k+1)<q[tail]&&(head==tail||max(last[q[tail]],i-k+1)>q[tail-1])&&f[max(last[q[tail]],i-k+1)-1]+val[last[q[tail]]]<=f[q[tail]-1]+val[q[tail]])
            {
                q[++tail]=q[tail];
                val[max(last[q[tail-1]],i-k+1)]=val[last[q[tail-1]]];
                q[tail-1]=max(last[q[tail-1]],i-k+1);
            }
        }
        else
        {
            last[i]=q[tail];
            val[i]=a[i];
            while(head<=tail&&f[i-1]+val[i]<=f[q[tail]-1]+val[q[tail]])
                tail--;
            q[++tail]=i;
        }
        // for(int i=head;i<=tail;i++)
        //     printf("%d ",q[i]);
        // puts("");
        f[i]=f[q[head]-1]+val[q[head]];
        printf("%d ",f[i]);
    }
    int ans=0;
    for(int i=n,w=1;i;i--,w=23ll*w%P)
        ans=(ans+f[i]%P*w%P)%P;
    printf("%d",ans);
    return 0;
}